﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAL;
using System.Data;
using BLL.Util;

namespace BLL
{
    public class OrganizationBLL
    {
        /// <summary>
        /// 获取所有组织机构
        /// </summary>
        /// <returns></returns>
        internal static List<Organization> GetAllOrganization()
        {
            OrganizationDAL dal = new OrganizationDAL();
            DataTable table = dal.GetAllTable();
            List<Organization> list = new List<Organization>();

            foreach (DataRow row in table.Rows)
            {
                Organization org = new Organization();
                org.ID = int.Parse(row["oid"].ToString());
                org.Title = row["title"].ToString();
                org.Url = row["URL"].ToString();
                org.Type = EnumHelper.GetEnumByValue<OrganizationType>(typeof(OrganizationType), row["type"].ToString());
                list.Add(org);
            }

            return list;
        }
        /// <summary>
        /// 获取组织机构
        /// </summary>
        /// <param name="id">组织机构ID</param>
        /// <returns></returns>
        public static Organization GetOrganizationById(int id)
        {
            var foo = from bar in CacheHelper.GetAllOrganization() where bar.ID == id select bar;
            return foo.SingleOrDefault();
        }
        /// <summary>
        /// 获取所有银行机构信息
        /// </summary>
        /// <returns>银行机构信息</returns>
        public static IEnumerable<Organization> GetAllBank()
        {
            var foo = from bar in CacheHelper.GetAllOrganization() where bar.Type == OrganizationType.Bank select bar;
            return foo;
        }
    }
}
